<template>
  <div class="app-container">
    <div class="diy-bg-white">
      <div class="diy-mx-5 diy-py-5">

        <!-- 切换/搜索 -->
        <div class="diy-flex diy-justify-between">
          <div class="diy-w-2/3">
            <el-radio-group v-model="queryParams.userLoginChannel" @input="handleQuery" style="margin-bottom: 30px;">
              <el-radio-button v-for="(dict,index) in dict.type.ELoginChannel" :key="index" :label="dict.value">
                {{dict.label}}
              </el-radio-button>
            </el-radio-group>
          </div>
          <div class="diy-w-1/3 diy-text-right">
            <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
              <el-form-item label="昵称" prop="nickname">
                <el-input
                  v-model="queryParams.nickname"
                  placeholder="请输入昵称"
                  clearable
                  style="width: 160px"
                />
              </el-form-item>
              <el-form-item label="手机号码" prop="phoneNumber">
                <el-input
                  v-model="queryParams.phoneNumber"
                  placeholder="请输入绑定手机号"
                  clearable
                  style="width: 160px"
                />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">查 询</el-button>
                <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
              </el-form-item>
            </el-form>
          </div>
        </div>

        <!-- 列表数据 -->
        <div class="">
          <el-table
            v-loading="loading"
            :data="dataList"
            :header-cell-style="{fontSize:'14px'}">
            <el-table-column type="index" align="center" width="50" label="序号" />
            <el-table-column prop="nickname" align="center" label="昵称" />
            <el-table-column prop="phoneNumber" align="center" label="手机号" />
            <el-table-column
              prop="userLoginChannel"
              align="center"
              label="账号类型">
              <template slot-scope="{row}">
                <dict-tag :options="dict.type.ELoginChannel" :value="row.userLoginChannel"/>
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              label="操作">
              <template slot-scope="{row}">
                <el-button
                  size="mini"
                  type="primary"
                  icon="el-icon-document"
                  v-if="row.phoneNumber"
                  @click="handleCheck(row)"
                >查看车牌
                </el-button>
                <el-button
                  size="mini"
                  type="primary"
                  icon="el-icon-document"
                  @click="handleCount(row)"
                >停车次数
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>

      </div>
    </div>

    <!-- 分页组件 -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 查看车牌弹框 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="openCount" width="1000px" append-to-body>
      <div class="">
        <el-table
          :data="dataInfo"
          :header-cell-style="{fontSize:'14px'}">
          <el-table-column prop="plateNumber" align="center" label="车牌号" />
          <el-table-column prop="phoneNumber" align="center" label="手机号" />
          <el-table-column prop="checkStatusStr" align="center" label="验证状态" />
          <el-table-column
            prop="userLoginChannel"
            align="center"
            label="渠道">
            <template slot-scope="{row}">
              <dict-tag :options="dict.type.ELoginChannel" :value="row.userLoginChannel"/>
            </template>
          </el-table-column>
          <el-table-column
            prop="type"
            align="center"
            label="车辆类型">
            <template slot-scope="{row}">
              <dict-tag :options="dict.type.EUserCarType" :value="row.type"/>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页组件 -->
        <pagination
          v-show="platTotal>0"
          :total="platTotal"
          :page.sync="platParams.page"
          :limit.sync="platParams.pageSize"
          @pagination="userCarList"
        />
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="openCount = false">确 定</el-button>
      </div>
    </el-dialog>

    <!-- 停车次数弹框 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="1300px" append-to-body>
      <!--检索-->
      <div>
        <el-form :model="carNoParams" ref="carNoParams" size="small" :inline="true" label-width="72px">
          <el-form-item label="具体时间" prop="dateRange">
            <el-date-picker
              v-model="carNoParams.dateRange"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="datetimerange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              style="width:360px;"
              :default-time="['00:00:00','23:59:59']"
            ></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="small" @click="handleQueryCount">查 询</el-button>
            <el-button icon="el-icon-refresh" size="small" @click="handleResetQuery">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      <!--数据-->
      <div class="">
        <el-table
          v-loading="loadingRecord"
          :data="dataRecord"
          :header-cell-style="{fontSize:'14px'}">
          <el-table-column prop="departmentName" align="center" label="机构名称" show-overflow-tooltip/>
          <el-table-column prop="parkName" align="center" label="片区名称" show-overflow-tooltip/>
          <el-table-column prop="id" width="148" align="center" label="停车记录ID" show-overflow-tooltip>
            <template slot-scope="{row}">
              <span class="diy-mr-2">{{ row.id }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="id" width="148" align="center" label="订单id" show-overflow-tooltip>
            <template slot-scope="{row}">
              <span class="diy-mr-2">{{ row.orderId }}</span>
            </template>
          </el-table-column>
          <el-table-column  prop="plateNumber" align="center" label="车牌" width="100" show-overflow-tooltip />
          <el-table-column  prop="type" align="center" label="车辆类型"  >
            <template slot-scope="{row}">
              <dict-tag :options="dict.type.ECarcomeType" :value="row.type"/>
            </template>
          </el-table-column>
          <el-table-column prop="phoneNumber" align="center" label="手机号" width="108" show-overflow-tooltip />
          <el-table-column prop="nickname" align="center" label="昵称" show-overflow-tooltip />
          <el-table-column prop="userLoginChannel" align="center" width="140" label="渠道" show-overflow-tooltip>
            <template slot-scope="{row}">
              <dict-tag :options="dict.type.ELoginChannel" :value="row.userLoginChannel" show-overflow-tooltip />
            </template>
          </el-table-column>
          <el-table-column prop="registerTime" width="180" align="center" label="确认停车" show-overflow-tooltip />
          <el-table-column prop="registerType" align="center" label="登记方式" show-overflow-tooltip>
            <template slot-scope="{row}">
              <dict-tag :options="dict.type.ECarcomeRegisterType" :value="row.registerType"/>
            </template>
          </el-table-column>
          <el-table-column prop="berthCode" align="center" label="泊位号" show-overflow-tooltip />
          <el-table-column prop="enterTime" align="center" width="180" label="开始时间" show-overflow-tooltip />
          <el-table-column prop="outTime" width="180" align="center" label="结束时间" show-overflow-tooltip />
          <el-table-column prop="durationStr" align="center" label="停车时长" show-overflow-tooltip />
        </el-table>
      </div>
      <!-- 分页组件 -->
      <pagination
        v-show="totalRecord>0"
        :total="totalRecord"
        :page.sync="carNoParams.page"
        :limit.sync="carNoParams.pageSize"
        @pagination="userOutdoorCarcomeList"
      />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancel">确 定</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {fetchList,userCarList,userOutdoorCarcomeList} from "@/api/carOwners/accountInfo";
export default {
  name: "AccountInfo",
  dicts: ['ELoginChannel','EUserCarType','ECarcomeType','ECarcomeRegisterType'],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 总条数
      total: 0,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层
      openCount: false,
      ///数据列表
      dataList: [],
      //查看车牌
      dataInfo: [],
      // 查询参数
      queryParams: {
        page: 1,
        pageSize: 10,
        userLoginChannel:1,
      },
      platParams:{//查看车牌查询条件
        page: 1,
        pageSize: 10,
      },
      platTotal:0,//查看车牌总条数
      platLodding:false,//查看车牌加载
      //停车次数
      dataRecord: [],
      // 停车次数遮罩层
      loadingRecord: false,
      // 停车次数总条数
      totalRecord: 0,
      // 停车次数搜索参数
      carNoParams: {
        page: 1,
        pageSize: 10,
        dateRange: []
      },
      
      
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 数据列表
    getList() {
      this.loading = true;
      fetchList(this.queryParams).then(response => {
        let data = response.data || {}
        this.dataList = data.list || []
        this.total = data.total;
        this.loading = false;
      });
    },
    // 搜索数据列表
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 搜索停车次数列表
    handleQueryCount() {
      this.carNoParams.page = 1;
      this.userOutdoorCarcomeList();
    },
    /** 停车次数重置按钮操作 */
    handleResetQuery() {
      this.resetForm("carNoParams");
      this.handleQueryCount();
    },
    // 停车次数
    handleCount(row) {
      this.title = '停车次数';
      this.open = true;
      this.carNoParams.id = row.id
      this.userOutdoorCarcomeList()
    },
    userOutdoorCarcomeList(){//停车次数数据
      this.loadingRecord = true;
      if(!this.carNoParams.dateRange) this.carNoParams.dateRange = []
      let carNoParams = {...this.carNoParams}
      if(this.carNoParams.dateRange.length) {
        carNoParams.startTime = this.carNoParams.dateRange[0]
        carNoParams.endTime = this.carNoParams.dateRange[1]
      }
      delete carNoParams.dateRange
      userOutdoorCarcomeList(carNoParams).then(response => {
        let data = response.data || {}
        this.dataRecord = data.list || []
        this.totalRecord = data.total;
        this.loadingRecord = false;
      });
    },
    // 查看车牌
    handleCheck(row) {
      this.title = '查看车牌';
      this.openCount = true;
      this.platParams.id = row.id
      this.userCarList()
    },
    userCarList(){//用户列表数据
      this.platLodding = true;
      userCarList(this.platParams).then(response => {
        let data = response.data || {}
        this.dataInfo = data.list || []
        this.platTotal = data.total;
        this.platLodding = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    // 复制成功
    clipboardSuccess() {
      this.$modal.msgSuccess("复制成功");
    },
  }
};
</script>
